var myfs = require("./_include/fs");
var jslist = myfs.ls("server/RESTAPI");
RESTlist = jslist.filter(function(fileName){
	var suffix = ".rest.js"
	return fileName.toLowerCase().substr(-suffix.length) == suffix;
});
module.exports = function setRouter(app){
	RESTlist.forEach(function(fileName){
		var RESTModule = require("../"+fileName);
		var prefix = RESTModule.prefix;
		delete RESTModule.prefix;

		var methodNames = Object.keys(RESTModule);
		methodNames.forEach(function(methodName){
			var methodSet = RESTModule[methodName];
			Object.keys(methodSet).forEach(function(extendURL){
				app.register(prefix+(extendURL==="/"?"":extendURL),[methodName],methodSet[extendURL]);
			});
		});

	});
	app.register("/gaubee",["get"],function *(next){
		console.log("????");
		yield next;
	});
}